// Package component
// @Author: zhengqi Wu
// @Description:
// @Version: 1.0.0
// @Date: 2021/4/23 11:20 上午
// @Copyright: MIN-Group；国家重大科技基础设施——未来网络北大实验室；深圳市信息论与未来网络重点实验室
//

const encoding = require("../encoding");
const {InitialAble, TlvComponentBase} = require("./TlvComponentBase");
const {Encoder, MaxPacketSize} = require("../encoding/Encoder")
let aggregation = require('../common/aggregation')//实现了多继承
class IncomingLogicFaceId extends aggregation(TlvComponentBase,InitialAble,encoding.IEncodingAble, encoding.SelfEncodingBase){
    get incomingLogicFaceId() {
        return this._incomingLogicFaceId;
    }

    set incomingLogicFaceId(value) {
        this._incomingLogicFaceId = value;
        this.doInitial()
    }
    constructor() {
        super();
        this._incomingLogicFaceId = BigInt(0)
    }

    wireEncode(enc){
        try{
            let totalLength = 0

            // 编码 TLV-VALUE
            let tmpLen = enc.prependNonNegativeInteger(this.incomingLogicFaceId)
            totalLength += tmpLen

            // 编码 TLV-LENGTH
            tmpLen = enc.prependVarNumber(totalLength)
            totalLength += tmpLen

            // 编码 TLV-TYPE
            tmpLen = enc.prependVarNumber(encoding.tlv.ComponentType.TlvIncomingLogicFaceId)
            totalLength += tmpLen

            return totalLength
        }catch (e) {
            throw e
        }

    }

    wireDecode(block){
        try{
            encoding.tlv.expectType(block.getType(), encoding.tlv.ComponentType.TlvIncomingLogicFaceId)

            let value = encoding.tlv.readNonNegativeInteger(block.getBuffer(), 0, block.getLength())
            this.incomingLogicFaceId = BigInt(value)
        }catch (e) {
            throw e
        }
    }
}

module.exports = {
    IncomingLogicFaceId: IncomingLogicFaceId
}